﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HumanWorkflow.Interface;

namespace OrderWorkflowTest
{
    public class OrderWorkflowTest
    {
    /*
        #region Generated code based simple workflow tests

        [TestMethod]
        public void GeneratedCode_ItemsAreMissingThreadTest()
        {
            var orderWorkflow = new OrderWorkflowWithGeneratedCode();
            orderWorkflow.StocksAreOk = false;
            ItemsAreMissingThread(orderWorkflow);
        }

        [TestMethod]
        public void GeneratedCode_ItemsAreAvailableThreadTest()
        {
            var orderWorkflow = new OrderWorkflowWithGeneratedCode();
            orderWorkflow.StocksAreOk = true;
            ItemsAreAvailableThread(orderWorkflow);
        }

        [TestMethod]
        public void GeneratedCode_StopWorkflowAtManualStepTest()
        {
            var orderWorkflow = new OrderWorkflowWithGeneratedCode();
            orderWorkflow.StocksAreOk = true;
            StopWorkflowAtManualStep(orderWorkflow);
        }

        #endregion
        
        #region Framework based simple workflow tests

        [TestMethod]
        public void Framework_ItemsAreMissingThreadTest()
        {
            OrderWorkflowWithFramework orderWorkflow = new OrderWorkflowWithFramework();
            orderWorkflow.StocksAreOk = false;
            ItemsAreMissingThread(orderWorkflow);
        }

        [TestMethod]
        public void Framework_ItemsAreAvailableThreadTest()
        {
            OrderWorkflowWithFramework orderWorkflow = new OrderWorkflowWithFramework();
            orderWorkflow.StocksAreOk = true;
            ItemsAreAvailableThread(orderWorkflow);
        }

        [TestMethod]
        public void Framework_StopWorkflowAtManualStepTest()
        {
            OrderWorkflowWithFramework orderWorkflow = new OrderWorkflowWithFramework();
            orderWorkflow.StocksAreOk = true;
            StopWorkflowAtManualStep(orderWorkflow);
        }

        #endregion

        #region Internal DSL workflow tests

        [TestMethod]
        public void InternalDsl_ItemsAreMissingThreadTest()
        {
            OrderWorkflowWithInternalDsl orderWorkflow = new OrderWorkflowWithInternalDsl();
            orderWorkflow.StocksAreOk = false;
            ItemsAreMissingThread(orderWorkflow);
        }

        [TestMethod]
        public void InternalDsl_ItemsAreAvailableThreadTest()
        {
            OrderWorkflowWithInternalDsl orderWorkflow = new OrderWorkflowWithInternalDsl();
            orderWorkflow.StocksAreOk = true;
            ItemsAreAvailableThread(orderWorkflow);
        }

        [TestMethod]
        public void InternalDsl_StopWorkflowAtManualStepTest()
        {
            OrderWorkflowWithInternalDsl orderWorkflow = new OrderWorkflowWithInternalDsl();
            orderWorkflow.StocksAreOk = true;
            StopWorkflowAtManualStep(orderWorkflow);
        }

        #endregion


        #endregion
        */
        #region General test methods

        public void ItemsAreMissingThread(IHumanWorkflow orderWorkflow)
        {
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.StartInitialStep);
            
            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.Start);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.ConcordeCustomerDataManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.CustomerCare);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.ConcordanceReady);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.CheckPossibleDiscountsManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.CustomerCare);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.DiscountCheckReady);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.OrderMissingItemsManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.OrderHandling);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.MissingItemsOrderDone);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.WaitForItemsToArriveManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.OrderHandling);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.MissingItemsArrived);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.ShipItemsManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.Inventory);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.ItemsShipped);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.FinishFinalStep);            
        }

        public void ItemsAreAvailableThread(IHumanWorkflow orderWorkflow)
        {
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.StartInitialStep);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.Start);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.ConcordeCustomerDataManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.CustomerCare);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.ConcordanceReady);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.CheckPossibleDiscountsManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.CustomerCare);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.DiscountCheckReady);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.ShipItemsManualStep);
            Assert.AreEqual(orderWorkflow.CurrentRole, OrderWorkflowConstants.Roles.Inventory);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.ItemsShipped);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.FinishFinalStep);                    
        }

        public void StopWorkflowAtManualStep(IHumanWorkflow orderWorkflow)
        {

            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.StartInitialStep);

            orderWorkflow.RaiseTransition(OrderWorkflowConstants.Transitions.Start);
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.ConcordeCustomerDataManualStep);

            orderWorkflow.RaiseTransition("ConcordeCustomerDataStopWorkflow");
            Assert.AreEqual(orderWorkflow.CurrentStep, OrderWorkflowConstants.Steps.FinishFinalStep);

        }

        #endregion
    }
}
